﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.IO;

namespace moveErrorFile.classes
{
    class clsEmailHelper
    {
        public static void sendEmail(out string sErrorMsg, string recipient, string subject, string body, string attachmentFilename)
        {
            sErrorMsg = null;

            string email = "henrywoo1978@gmail.com";
            string password = "#Iphone1978";

            var loginInfo = new NetworkCredential(email, password);
            MailMessage msg = new MailMessage();
            var smtpClient = new SmtpClient("smtp.gmail.com", 587);

            msg.From = new MailAddress(email);
            msg.To.Add(new MailAddress("henry.woo@keppellog.com"));
            msg.Subject = subject;
            msg.Body = body;
            msg.IsBodyHtml = true;

            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = loginInfo;

            try
            {
                if (!string.IsNullOrEmpty(attachmentFilename))
                {
                    if (File.Exists(attachmentFilename))
                    {
                        Attachment att = new Attachment(attachmentFilename);
                        msg.Attachments.Add(att);
                    }

                }


                smtpClient.Send(msg);
            }
            catch (Exception ex)
            {
                sErrorMsg = ex.Message;
            }
        }

    }
}
